package top.sqdpt.pt.statemachine;

import java.util.ArrayList;
import java.util.List;

/**
 * 使用构造器方便注册状态机
 *
 * @param <S> 状态枚举
 * @param <E> 事件枚举
 */
public class PtStateTranslateBuilder<S extends Enum<S>, E extends Enum<E>> {
    private final List<PtStateTranslate<S, E>> ptStateTranslates = new ArrayList<>();

    public PtStateTranslateBuilder<S, E> addTranslate(S sourceState, S targetState, E stateEvent, PtStateAction<S> action) {
        ptStateTranslates.add(new PtStateTranslate<>(sourceState, targetState, new PtStateEvent<>(stateEvent, action)));
        return this;
    }

    public PtStateTranslateBuilder<S, E> addEasyStateAction(PtEasyStateAction<S,  E> ptEasyStateAction) {
        ptStateTranslates.add(new PtStateTranslate<>(ptEasyStateAction.getStartState(), ptEasyStateAction.getTargetState(), new PtStateEvent<>(ptEasyStateAction.getEvent(), ptEasyStateAction)));
        return this;
    }

    public List<PtStateTranslate<S, E>> build() {
        return ptStateTranslates;
    }

}
